   /*the default options for jquery.form plugin */
   var options = {
        beforeSubmit:  ShowLoader,  // pre-submit callback
        success:       showResponse,  // post-submit callback
        dataType:   "json"        // 'xml', 'script', or 'json' (expected server response type)
    };


	function showResponse(data, statusText, xhr, $form){
      if(data.success){
    	  $("#message").html('<div class="success">'+data.success+'</div>').show();
    	  //$("form").resetForm();
    	  window.location = data.link;
    	  
    	  $("#accountFromErr").parent().removeClass("error-validator");
    	  $("#accountFromErr").html("");
    	  $("#accountToErr").parent().removeClass("error-validator");
    	  $("#accountToErr").html("");
    	  $("#ammountErr").parent().removeClass("error-validator");
    	  $("#ammountErr").html("");
    	  
    	  
    	  
    	 
      }
      if(data.error){
    	  if(data.islogin){
    		  alert(data.error);
    	  }
    	  else{
	    	  $("#accountFromErr").parent().removeClass("error-validator");
	    	  if(data.error.accountFrom){
	    		  $("#accountFromErr").parent().addClass("error-validator");
	    		  $("#accountFromErr").html(data.error.accountFrom);
	    	  }
	    	  else{
	    		  $("#accountFromErr").html("");
	    	  }
	    	  
	    	  $("#accountToErr").parent().removeClass("error-validator");
	    	  if(data.error.accountTo){
	    		  $("#accountToErr").parent().addClass("error-validator");
	    		  $("#accountToErr").html(data.error.accountTo);
	    	  }
	    	  else{
	    		  $("#accountToErr").html("");
	    	  }
	    	  
	    	  $("#ammountErr").parent().removeClass("error-validator");
	    	  if(data.error.ammount){
	    		  $("#ammountErr").parent().addClass("error-validator");
	    		  $("#ammountErr").html(data.error.ammount);
	    	  }
	    	  else{
	    		  $("#ammountErr").html("");
	    	  }
	    	  
	    	  $("div.form #internalTransferForm span.error-validator").show();
	    	  $("#message").html('<div class="error">' + data.error.message +'</div>').show();
	    	  window.location = data.link;
    	  }
      }
      if(data.refresh){
    	  var delay = 0;
    	  if(data.delay){
    		  delay = data.delay;
    	  }
    	  else{
    		  delay = 1;
    	  }
    	  setTimeout("location.reload(true)", delay*1000); 
      }
      if(data.redirect)	{
    	  var delay = 0;
    	  if(data.delay){
    		  delay = data.delay;
    	  }
    	  else{
    		  delay = 1;
    	  }
    	  setTimeout("window.location = '" + data.redirect + "'", delay*1000);
      }
      if(data.back)	{
		history.back();
  	 }
  	 
      HideLoader();
   }

  function ShowLoader()
   {
	 
	  
     var h=$(window).height();
     $("#loader").css({height:h, opacity: 0.5});
     $("#loaderimg").css({margin: h/2-200});
     $("#loader").show();
   }
  function HideLoader()
   {
     $("#loader").hide();
   }
  
   /* Submit a form, ajax post method */
   function Send(id_form){
       $(id_form).ajaxSubmit(options);
	   return false;
   }